/*
*  Copyright (c) 2006-2020, Chukie
*  
*  SPDX-License-Identifier: Apache-2.0
*  
*  @file     : cellular_ppp.h
*  
*  @brief    : 
*  Website   : https://gitee.com/open-embedded
*  
*  
*  Change Logs:
*  Date           Author          Notes
*  2020-06-23     zhaocj       The first version
*/
/* Define to prevent recursive inclusion ------------------------------------*/
#ifndef __CELLULAR_PPP_H__
#define __CELLULAR_PPP_H__
/* Includes -----------------------------------------------------------------*/
#include "cellular_def.h"

#include "netif/ppp/pppos.h"
#include "lwip/netif.h"
#include <cellular_netdev.h>
#ifdef __cplusplus
extern "C"
{
#endif /*__cplusplus*/
/* Exported types -----------------------------------------------------------*/
#define CELLULAR_PPP_THREAD_NAME        "pppd"
#define CELLULAR_PPP_THREAD_PRIO        (RT_LWIP_TCPTHREAD_PRIORITY > 0 ? (RT_LWIP_TCPTHREAD_PRIORITY - 1) : RT_LWIP_TCPTHREAD_PRIORITY) 
#define CELLULAR_PPP_THREAD_STACK_SIZE  2048
#define CELLULAR_PPP_THREAD_TIMESLICE   16

typedef enum{
    PPP_AUTH_TYPE_NONE = PPPAUTHTYPE_NONE,
    PPP_AUTH_TYPE_PAP = PPPAUTHTYPE_PAP,
    PPP_AUTH_TYPE_CHAP = PPPAUTHTYPE_CHAP,
    PPP_AUTH_TYPE_MSCHAP = PPPAUTHTYPE_MSCHAP,
    PPP_AUTH_TYPE_MSCHAP_V2 = PPPAUTHTYPE_MSCHAP_V2,
    PPP_AUTH_TYPE_EAP = PPPAUTHTYPE_EAP,
}ppp_auth_type_t;

struct cellular_ppp_config{
    /*Auth type required for ppp authentication,reference to ppp.h: 
    availabel value: PPPAUTHTYPE_NONE/PPPAUTHTYPE_PAP/PPPAUTHTYPE_CHAP */
    ppp_auth_type_t auth;
    char dial_number[CELLULAR_PPP_MAX_DIAL_NUMBER_LEN + 1];
    /*Username required for ppp authentication*/
    char user_name[CELLULAR_PPP_MAX_USERNAME_LEN+1];
    /*Password required for ppp authentication*/
    char password[CELLULAR_PPP_MAX_USERNAME_LEN+1];
}__PACKED;
typedef struct cellular_ppp_config *cellular_ppp_config_t;

struct cellular_ppp
{
    volatile int running;
    struct rt_thread thread;
    struct rt_semaphore rx_sem;
    struct rt_semaphore tx_sem;
    struct rt_event event;

    rt_device_t device;
    
#ifdef RT_USING_NETDEV
    /* netdev */
    struct netdev netdev;
#endif /*RT_USING_NETDEV*/
    /* network interface for lwip */
    struct netif netif;
    /*pointer to ppp control block*/
    ppp_pcb *pcb;
    /*config*/
    cellular_ppp_config_t config;
    uint32_t rx_bytes;
    uint32_t tx_bytes;
    uint32_t ppp_drop_bytes;
    uint32_t ppp_drop_pkts;
    time_t connected_ts;
    void (*user_hook)(int status, int event);
    char stack[CELLULAR_PPP_THREAD_STACK_SIZE];
    char buffer[PPP_MAXMRU];
};
typedef struct cellular_ppp* cellular_ppp_t;
/* Exported constants -------------------------------------------------------*/
/* Exported macro -----------------------------------------------------------*/

/* Exported functions -------------------------------------------------------*/


#ifdef __cplusplus
{
#endif /*__cplusplus*/
#endif /*__CELLULAR_PPP_H__*/
/* End of file****************************************************************/

